#ifndef __DL_SERVICE__
#define __DL_SERVICE__

#include "Type_Define.h"
 
#include "IO_LINK_Global_Param.h"
#include "DL_Message_Handler.h"
#include "DL_OD_Handler.h"
#include "IO_LINK_DataBuffer.h"
#include "DL_Mode_Handler.h"
#include "DL_ISDU_Handler.h"
#include "DL_Service.h"
#include <stdio.h>
#include <stdlib.h>
#include "DL_EH.h"
#include "DL_CH.h"
#include "SM.h"
#include <string.h>


 

typedef struct{
   uint16_t M_squenceTime;
   M_sequnceTypeDef M_sequnceType;
   uint8_t PDInputLength;
   uint8_t PDOutputLength;
   uint8_t ODLength;
   
}DL_SetMode_ValueList_StructTypeDef;


typedef struct{
  uint16_t  Index;
  uint8_t Subindex;
  uint8_t * OctectString ; //具体长度由IOOD在fixedLength中设定，最大为232
  uint8_t OctectStringLen; //数据长度，需小于232
  DirectionTypeDef Diriction;
}ISDU_ValueList_Typedef;

typedef enum{
   PDin_VALID,   //输入有效
   PDin_INVALID, //输入无效
   PDOUTVALID,
   PDOUTINVALID
}ControlCode_TYPE;

typedef enum{
	DL_Service_No_ERROR,
	DL_Service_STATE_CONFLICT
	
}DL_Service_ErrorInfo_TYPE;



//通信锁,用于防止多个service同时访问通道
extern Service_LOCK_TYPE Page_Lock[PORT_NUM];
extern Service_LOCK_TYPE ISDU_Lock[PORT_NUM];
extern Service_LOCK_TYPE Event_Lock[PORT_NUM];

void Event_DL_Mode_COMLOST(uint8_t Port);//DL_Mode_COMLOST函数原型
 
RESULT_TYPE Service_DL_Read(uint8_t Port,uint8_t Address,uint8_t * Result);
RESULT_TYPE Service_DL_Write(uint8_t Port,uint8_t Address,uint8_t Data);
void Service_DL_Write_Cnf(uint8_t Port);
void Service_DL_Read_Cnf(uint8_t Port,uint8_t Data);
RESULT_TYPE Service_DL_ISDUTransport(uint8_t Port,ISDU_ValueList_Typedef ISDU_ValueList);
 
RESULT_TYPE Service_DL_ReadParam(uint8_t Port,uint8_t Address);
void Service_DL_ReadParam_Cnf(uint8_t Port,uint8_t Data);
RESULT_TYPE Service_DL_WriteParam(uint8_t Port,uint8_t Address,uint8_t Data);
void Service_DL_WriteParam_Cnf(uint8_t Port);
RESULT_TYPE Service_DL_SetMode(uint8_t Port,SM_DL_STATE_TYPE Mode,DL_SetMode_ValueList_StructTypeDef ValueList);

 
 
 
 //辅助函数
 
 void MC_Struct_INIT(uint8_t Port);
 void  MC_Struct_Process (uint8_t  Port, DL_SetMode_ValueList_StructTypeDef ValueList) ;
#endif
